
package cn.bocai.pc.web.portal.verificationCode;

import javax.servlet.ServletException;         
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;         
import javax.servlet.http.HttpServletResponse;         
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/Verify")
public class VerifyCodeController{
  
    @RequestMapping(value="/verifyCode")
    public void service(HttpServletRequest req, HttpServletResponse response)         
            throws ServletException, java.io.IOException { 
    	 // 设置响应的类型格式为图片格式  
        response.setContentType("image/jpeg");  
        // 禁止图像缓存。  
        response.setHeader("Pragma", "no-cache");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setDateHeader("Expires", 0);  
        SCaptcha instance = new SCaptcha(); 
        // 将四位数字的验证码保存到Session中。         
        HttpSession session = req.getSession();         
        session.setAttribute("validateCode", instance.getCode());  
        
        Cookie cookie = new Cookie("scaptcha", instance.getCode());  
        cookie.setMaxAge(1800);  
        response.addCookie(cookie);  
        instance.write(response.getOutputStream());  
       
    }         
}
